﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using Quartz.Impl;

namespace ConsoleApp
{
    public static class demo_quartz
    {
        public static void demo()
        {
            lesson1();            
        }

        private static void lesson1()
        {
            ISchedulerFactory schedFact = new StdSchedulerFactory();

            // get a scheduler
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();

            IJobDetail job = JobBuilder.Create<HelloJob>()
                .WithIdentity("hellojob", "hellogroup")
                .UsingJobData("jobsay", "hello,51")
                .Build();

            // Trigger the job to run now, and then every 40 seconds
            ITrigger trigger = TriggerBuilder.Create()
              .WithIdentity("helloTrigger", "hellogroup")
              .StartNow()
              .WithSimpleSchedule(x => x
                  .WithIntervalInSeconds(60)
                  .RepeatForever())
              .Build();

            sched.ScheduleJob(job, trigger);
        }
    }

    public class HelloJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            System.Threading.Thread.Sleep(1000 * 60 * 1);
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            System.Console.WriteLine(DateTime.Now.ToString() + " , " + dataMap.GetString("jobsay"));         
        }
    }
}